/**
 * Created by vincent on 2017/9/20.
 */
moduleStudyMap.controller("SetMicroH5Controller", function ($$CambioConfig, $scope, $log, $state, LoadingService, DialogService,
                                                            EnumService, ConstantService, StudyClassResource) {
    $scope.$on("ngDialog.opened", function () {
        dialogOnLoad();
        getMicroH5StudyClass();
    });

    var getMicroH5StudyClass = function () {
        if (StringUtils.isNlOrUndOrEmpty($scope.currentStudyClass.targetId)) {
            $scope.setMicroH5StudyClass = {};
        } else {
            //LoadingService.show();
            StudyClassResource.getTarget({studyClassId: $scope.currentStudyClass.id}, function (microH5StudyClassResult) {
                $log.debug("课程相关微课信息", microH5StudyClassResult);
                $scope.setMicroH5StudyClass = microH5StudyClassResult;
                //LoadingService.hide();
            }, function () {
                //LoadingService.hide();
            });
        }
    };

    $scope.cancel = function () {
        DialogService.close();
    };

    $scope.submit = function () {
        if ($scope.setMHSCForm.$valid) {
            //LoadingService.show();
            StudyClassResource.setMicroH5({studyClassId: $scope.currentStudyClass.id}, $scope.setMicroH5StudyClass, function (studyClassResult) {
                $log.debug("设置课程微课结果", studyClassResult);
                angular.copy(studyClassResult, $scope.currentStudyClass);
                DialogService.close();
                //LoadingService.hide();
                Alert.success("设置微课成功！");
            }, function () {
                //LoadingService.hide();
            });
        }
    };

});